﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ElementumForever.Interfaces;
using Microsoft.Xna.Framework;
using ElementumForever.Utility;

namespace ElementumForever.Scene
{
    public abstract class CameraScene : BaseScene
    {
        public ICamera Camera { get; private set; }
        public CameraScene(MainGame game, ICamera camera)
            : base(game)
        {
            this.Camera = camera;
        }

        public override void OnCreat()
        {
            base.OnCreat();
            RegistUpdateHandler(this.Camera);
        }

        protected override void UpdateTransform()
        {
            Matrix parentTransform = Matrix.Identity;
            Matrix cameraTransform = this.Camera.Projection;
            if (Parent != null)
                parentTransform = Parent.Projection;
            _projectionMatrix = CoordinateHelper.ChildToParentTransformMatrix(this) * cameraTransform * parentTransform;
        }

        public override Matrix Unprojection
        {
            get
            {
                return base.Unprojection*Camera.Unprojection;
            }
        }

    }
}
